// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class QUERY_RESPONSE_ADR_A19 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("12 EVN",12)]
  	    [HL7Field(HL7Version.v23, 12, HL7Repeat.False, HL7Required.False,"EVN")]
	    public EVN EVN {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("14 PID",14)]
  	    [HL7Field(HL7Version.v23, 14, HL7Repeat.False, HL7Required.True,"PID")]
	    public PID PID {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("16 PD1",16)]
  	    [HL7Field(HL7Version.v23, 16, HL7Repeat.False, HL7Required.False,"PD1")]
	    public PD1 PD1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("20 NK1",20)]
  	    [HL7Field(HL7Version.v23, 20, HL7Repeat.True, HL7Required.False,"NK1")]
	    public NK1[] NK1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("23 PV1",23)]
  	    [HL7Field(HL7Version.v23, 23, HL7Repeat.False, HL7Required.True,"PV1")]
	    public PV1 PV1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("25 PV2",25)]
  	    [HL7Field(HL7Version.v23, 25, HL7Repeat.False, HL7Required.False,"PV2")]
	    public PV2 PV2 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("29 DB1",29)]
  	    [HL7Field(HL7Version.v23, 29, HL7Repeat.True, HL7Required.False,"DB1")]
	    public DB1[] DB1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("34 OBX",34)]
  	    [HL7Field(HL7Version.v23, 34, HL7Repeat.True, HL7Required.False,"OBX")]
	    public OBX[] OBX {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("39 AL1",39)]
  	    [HL7Field(HL7Version.v23, 39, HL7Repeat.True, HL7Required.False,"AL1")]
	    public AL1[] AL1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("44 DG1",44)]
  	    [HL7Field(HL7Version.v23, 44, HL7Repeat.True, HL7Required.False,"DG1")]
	    public DG1[] DG1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("48 DRG",48)]
  	    [HL7Field(HL7Version.v23, 48, HL7Repeat.False, HL7Required.False,"DRG")]
	    public DRG DRG {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("50 PROCEDURE",50)]
  	    [HL7Field(HL7Version.v23, 50, HL7Repeat.False, HL7Required.False,"PROCEDURE_ADR_A19")]
	    public PROCEDURE_ADR_A19 PROCEDURE {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			EVN = PopSegmentParseAndCheckRequired<EVN>(availableData, options, "EVN");
			PID = PopSegmentParseAndCheckRequired<PID>(availableData, options, "PID");
			PD1 = PopSegmentParseAndCheckRequired<PD1>(availableData, options, "PD1");
			NK1 = PopSegmentParseAndCheckRequiredArray<NK1>(availableData, options, "NK1");
			PV1 = PopSegmentParseAndCheckRequired<PV1>(availableData, options, "PV1");
			PV2 = PopSegmentParseAndCheckRequired<PV2>(availableData, options, "PV2");
			DB1 = PopSegmentParseAndCheckRequiredArray<DB1>(availableData, options, "DB1");
			OBX = PopSegmentParseAndCheckRequiredArray<OBX>(availableData, options, "OBX");
			AL1 = PopSegmentParseAndCheckRequiredArray<AL1>(availableData, options, "AL1");
			DG1 = PopSegmentParseAndCheckRequiredArray<DG1>(availableData, options, "DG1");
			DRG = PopSegmentParseAndCheckRequired<DRG>(availableData, options, "DRG");
			PROCEDURE = ProcessGroup<PROCEDURE_ADR_A19>(availableData, options, "PROCEDURE");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isEVN = availableData.StartsWith("EVN", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("EVN", options.Version) || isEVN) {
				return isEVN;
			}
			bool isPID = availableData.StartsWith("PID", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PID", options.Version) || isPID) {
				return isPID;
			}
			bool isPD1 = availableData.StartsWith("PD1", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PD1", options.Version) || isPD1) {
				return isPD1;
			}
			bool isNK1 = availableData.StartsWith("NK1", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("NK1", options.Version) || isNK1) {
				return isNK1;
			}
			bool isPV1 = availableData.StartsWith("PV1", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PV1", options.Version) || isPV1) {
				return isPV1;
			}
			bool isPV2 = availableData.StartsWith("PV2", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PV2", options.Version) || isPV2) {
				return isPV2;
			}
			bool isDB1 = availableData.StartsWith("DB1", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("DB1", options.Version) || isDB1) {
				return isDB1;
			}
			bool isOBX = availableData.StartsWith("OBX", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("OBX", options.Version) || isOBX) {
				return isOBX;
			}
			bool isAL1 = availableData.StartsWith("AL1", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("AL1", options.Version) || isAL1) {
				return isAL1;
			}
			bool isDG1 = availableData.StartsWith("DG1", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("DG1", options.Version) || isDG1) {
				return isDG1;
			}
			bool isDRG = availableData.StartsWith("DRG", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("DRG", options.Version) || isDRG) {
				return isDRG;
			}
			PROCEDURE_ADR_A19 testPROCEDURE_ADR_A19 = new PROCEDURE_ADR_A19();
			bool grpCCPROCEDURE_ADR_A19 = (testPROCEDURE_ADR_A19.CanConsume(availableData, options));
			if (IsRequired("PROCEDURE", options.Version) || grpCCPROCEDURE_ADR_A19) {
				return grpCCPROCEDURE_ADR_A19;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "QUERY_RESPONSE";
			}
        }

        static QUERY_RESPONSE_ADR_A19() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(QUERY_RESPONSE_ADR_A19));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (EVN != null) {
			string segmentValue = EVN.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (PID != null) {
			string segmentValue = PID.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (PD1 != null) {
			string segmentValue = PD1.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (NK1 != null && NK1.Length > 0) {
			for (int i = 0; i < NK1.Length; i++) {
				string segmentValue = NK1[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (PV1 != null) {
			string segmentValue = PV1.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (PV2 != null) {
			string segmentValue = PV2.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (DB1 != null && DB1.Length > 0) {
			for (int i = 0; i < DB1.Length; i++) {
				string segmentValue = DB1[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (OBX != null && OBX.Length > 0) {
			for (int i = 0; i < OBX.Length; i++) {
				string segmentValue = OBX[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (AL1 != null && AL1.Length > 0) {
			for (int i = 0; i < AL1.Length; i++) {
				string segmentValue = AL1[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (DG1 != null && DG1.Length > 0) {
			for (int i = 0; i < DG1.Length; i++) {
				string segmentValue = DG1[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (DRG != null) {
			string segmentValue = DRG.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (PROCEDURE != null) {
			string segmentValue = PROCEDURE.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

